#include <bits/stdc++.h>

using namespace std;

int ans[33][33],mp[33][33],n;
int xx[] = {0,0,-1,+1};
int yy[] = {+1,-1,0,0};
int main()
{
    cin>>n;
    for(int i =1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>mp[i][j];
        }
    }
    queue <int> x;
    queue <int> y;
    x.push(0);
    y.push(0);
    ans[0][0]=1;
    while(!x.empty()){
        int tx = x.front();
        int ty = y.front();
        for(int i=0;i<4;i++){
            int dx = xx[i]+tx;
            int dy = yy[i]+ty;
            if(dx<=n+1&&dx>=0&&dy<=n+1&&dy>=0&&mp[dx][dy]==0&&ans[dx][dy]==0){
                ans[dx][dy] = 1;
                x.push(dx);
                y.push(dy);
            }
        }
        x.pop();
        y.pop();
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(ans[i][j]==1){
                cout<<0<<' ';
                continue;
            }
            if(mp[i][j]==1){
                cout<<mp[i][j]<<' ';
            }
            else cout<<"2 ";
        }
        cout<<endl;
    }
    return 0;
}
